package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dao.ProductDao;
import domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {

    @Autowired
    private ProductDao productDao;

    //查询所有
    public PageInfo<Product> findAllProduct(int pageSize, int pageNum) {

        PageHelper.startPage(pageNum, pageSize);
        List<Product> products = productDao.findAll();
        PageInfo pageInfo = new PageInfo(products);
       return pageInfo;
    }

    //根据id查询
    public Product findProductById(int id) {
        return productDao.findById(id);
    }

    //新增
    public void addProduct(Product product) {
        productDao.add(product);
    }

    //产品修改
    public void updateProduct(Product product){
        productDao.update(product);
    }
    //修改产品状态
    public void updateProductStatus(int[] id, int status){
        for (int id1:id){
            Product product = new Product();
            product.setId(id1);
            product.setStatus(status);
            productDao.updateStatus(product);
        }
    }

    //产品删除
    public void delProduct(int[] ids){
        for (int id:ids){
            productDao.del(id);
        }
    }
}
